<?php

namespace App\Admin\Controllers;

use App\Admin\Extensions\Tools\ExportButton;
use App\Admin\Repositories\AnswerSurveySubject;
use App\Models\AnswerSurvey;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;
use Dcat\EasyExcel\Excel;

class AnswerSurveySubjectController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(AnswerSurveySubject::with('answer'), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('answer.title', admin_trans('answer-survey-subject.fields.answer_title'));
            $grid->column('title');
            $grid->column('type')->using(admin_trans('answer-survey-subject.options.type'));
//            $grid->column('score');
            $grid->column('status')->using(admin_trans('answer-survey-subject.options.status'));
            $grid->column('created_at');

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
        
            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, AnswerSurveySubject::with('answer'), function (Show $show) {
            $show->field('id');
            $show->field('answer.title', admin_trans('answer-survey-subject.fields.answer_title'));
            $show->field('title');
            $show->field('type')->using(admin_trans('answer-survey-subject.options.type'));
//            $show->field('score');
            $show->field('status')->using(admin_trans('answer-survey-subject.options.status'));
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new AnswerSurveySubject(), function (Form $form) {
            $form->display('id');
            $form->select('answer_id')
                ->options(AnswerSurvey::where('status', DEFAULT_STATUS_SUCCESS)
                    ->pluck('title', 'id'))
                ->required();
            $form->text('title');
//            $form->text('score');
            $form->radio('type')->options(admin_trans('answer-survey-subject.options.type'))->default('1');
            $form->radio('status')->options(admin_trans('answer-survey-subject.options.status'))->default('1');
        
            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
